package org.darack_application;

import android.annotation.*;
import android.app.*;
import android.app.AlertDialog.Builder;
import android.content.*;
import android.graphics.*;
import android.os.*;
import android.view.*;
import android.webkit.*;
import android.widget.*;

@SuppressLint("SetJavaScriptEnabled")
public class EnrolledActivity extends Activity {
	WebView browser;
	final Activity activity = this;
	ProgressDialog mProgress;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_board);
		browser=(WebView)findViewById(R.id.webkit_board);
		browser.setWebViewClient(new WebViewCallBack());
		WebSettings set=browser.getSettings();
		set.setBuiltInZoomControls(true);
		browser.getSettings().setJavaScriptEnabled(true);
		browser.loadUrl("http://hotsun2810.cafe24.com/xe/mobile/enrolled");
	}
	
	public boolean onKeyDown(int keyCode,KeyEvent event){
		if((keyCode==KeyEvent.KEYCODE_BACK)&&browser.canGoBack()){
			browser.goBack();
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}

	public class WebViewCallBack extends WebViewClient{
		@Override
		public boolean shouldOverrideUrlLoading(WebView view, String url) {
			view.loadUrl(url);
			return true;
		}
		
		@Override
		public void onPageStarted(WebView view, String url, Bitmap favicon) {
			if (mProgress == null) {
				mProgress = new ProgressDialog(activity);
				mProgress.setProgressStyle(ProgressDialog.STYLE_SPINNER);
//				mProgress.setTitle("Loading...");
				mProgress.setMessage("Loading, Please Wait..");
				mProgress.setCancelable(false);
				mProgress.setButton("Cancel", new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int whichButton) {
						mProgress.dismiss();
					}
				});
				mProgress.show();
			}
		}

		@Override
		public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
			Toast.makeText(activity, "Loading Error" + description, Toast.LENGTH_SHORT).show();

			if (mProgress.isShowing()) {
				mProgress.dismiss();
			}
		}

		@Override
		public void onPageFinished(WebView view, String url) {
			if (mProgress.isShowing()) {
				mProgress.dismiss();
			}
		}
	}
	
	public void onBackPressed() {
		Builder d = new AlertDialog.Builder(this);
		d.setMessage("정말 종료하시겠습니까?");
		d.setPositiveButton("예", new DialogInterface.OnClickListener() {

			public void onClick(DialogInterface dialog, int which) {
				// process전체 종료
				finish();
			}
		});
		d.setNegativeButton("아니요", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int which) {
				dialog.cancel();
			}
		});
		d.show();
	} 
}